package com.chwn.curiousdiary.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;

import com.chwn.curiousdiary.gloable.Constant;
import com.chwn.curiousdiary.service.AudioService;

/**
 * Created by myshikin on 2017/7/18.
 * 通知栏音频播放控制
 */
public class StatusBarReceiver extends BroadcastReceiver {
    public static final String ACTION_STATUS_BAR    = "com.chwn.curiousdiary.STATUS_BAR_ACTIONS";
    public static final String ACTION_STATUS_PRO    = "com.chwn.curiousdiary.STATUS_PRO_ACTIONS";
    public static final String ACTION_STATUS_NEXT   = "com.chwn.curiousdiary.STATUS_NEXT_ACTIONS";
    public static final String ACTION_STATUS_SWITCH = "com.chwn.curiousdiary.STATUS_SWITCH_ACTIONS";
    public static final String ACTION_STATUS_CLOSE  = "com.chwn.curiousdiary.STATUS_CLOSE_ACTIONS";
    public static final String EXTRA                = "extra";
    public static final String EXTRA_NEXT           = "next";
    public static final String EXTRA_PRO            = "pro";
    public static final String EXTRA_CLOSE_SELF     = "close_self";
    public static final String EXTRA_PLAY_PAUSE     = "play_pause";

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent == null || TextUtils.isEmpty(intent.getAction())) {
            return;
        }

        String extra = intent.getStringExtra(EXTRA);
        intent.setClass(context, AudioService.class);
        if (TextUtils.equals(extra, EXTRA_NEXT)) { //下一首
            intent.putExtra(Constant.STORY_SERVICE_TYPE, AudioService.NOTIFY_NEXT);
            context.startService(intent);
        } else if (TextUtils.equals(extra, EXTRA_PLAY_PAUSE)) {  //暂停&开始
            intent.putExtra(Constant.STORY_SERVICE_TYPE, AudioService.NOTIFY_PLAY_SWITCH);
            context.startService(intent);
        } else if (TextUtils.equals(extra, EXTRA_PRO)) {//上一首
            intent.putExtra(Constant.STORY_SERVICE_TYPE, AudioService.NOTIFY_PRE);
            context.startService(intent);
        } else if (TextUtils.equals(extra, EXTRA_CLOSE_SELF)) {//关闭通知栏 停止播放
            intent.putExtra(Constant.STORY_SERVICE_TYPE, AudioService.NOTIFY_CLOSE);
            context.startService(intent);
        }
    }
}
